package pers.fjl.test.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;
import pers.fjl.common.constant.MessageConstant;
import pers.fjl.common.entity.QueryPageBean;
import pers.fjl.common.entity.Result;
import pers.fjl.common.po.User;
import pers.fjl.test.annotation.LoginRequired;
import pers.fjl.test.service.RoleService;
import pers.fjl.test.service.WarehouseService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 角色管理模块
 *
 * @author fangjiale 2020年1月3日
 */

@Api(value = "权限管理列表", description = "权限管理的接口信息")
@RequestMapping("/role1")
@RestController
@CrossOrigin
public class RoleController {
    @Resource
    private RoleService roleService;

    @LoginRequired
    @ApiOperation(value = "分页查询", notes = "返回分页数据")
    @PostMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        return new Result(true, MessageConstant.OK, "获取分页数据成功", roleService.findPage(queryPageBean));
    }

    @LoginRequired
    @GetMapping("/menu")
    public Result getMenu(HttpServletRequest request) {
        // 获取到当前域中的user
        User user = (User) request.getAttribute("currentUser");
        System.out.println(user);
        return new Result(true, MessageConstant.OK, "获取菜单列表数据成功", roleService.getMenu(user.getRid()));
    }
}
